package com.example.practice;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class SettingActivity extends AppCompatActivity implements View.OnClickListener {

    private EditText sServer;
    private EditText sPort;
    private Button sPreservation;
    private Button sCancel;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_setting);
        initView();
    }

    private void initView() {
        sServer = (EditText) findViewById(R.id.s_server);
        sPort = (EditText) findViewById(R.id.s_port);
        sPreservation = (Button) findViewById(R.id.s_preservation);
        sCancel = (Button) findViewById(R.id.s_cancel);

        sPreservation.setOnClickListener(this);
        sCancel.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.s_preservation:

                break;
            case R.id.s_cancel:

                break;
        }
    }

    private void submit() {
        // validate
        String server = sServer.getText().toString().trim();
        if (TextUtils.isEmpty(server)) {
//            Toast.makeText(this, "192.168.1.196", Toast.LENGTH_SHORT).show();
        }
        String port = sPort.getText().toString().trim();
        if (TextUtils.isEmpty(port)&&0<=Integer.parseInt(port)&&65535>=Integer.parseInt(port)) {

        }else {
            Toast.makeText(this, "端口号错误", Toast.LENGTH_SHORT).show();
        }

        // TODO validate success, do something


    }
}
